import React from 'react';
import {
  Platform,
} from 'react-native';

import ShuwuRequestJumpUrl from '../../actions/shuwu/ShuwuRequestJumpUrl';
import WebViewPage from '../common/WebViewPage';

export default class ShuwuMainPage extends WebViewPage {

  constructor(props) {
    super(props);

    this._init = false;
    this.state.webUrl = "";
  }

  componentDidMount() {
    super.componentDidMount();
    new ShuwuRequestJumpUrl().call(this);
  }

  _dealEnterPage() {
    super._dealEnterPage();
    if (this._customUrl.length>0) {
      this.setState({
        source:this._customUrl,
      })
    }
    // new ShuwuRequestJumpUrl().call(this);
  }
  _dealLeavePage(){
    this.setState({
      source:null,
    },()=>{
       super._dealLeavePage();
    })
  }
  _onNavigationStateChange(navState){
    // console.log("_onNavigationStateChange", navState.url, navState);
    this.setState({
      url: navState.url,
    });
  }

  isRenderWebView(){
    return this.state.webUrl != "" || this._init === true;
  }

  _onShouldStartLoadWithRequest(event) {
    // if(event.url.indexOf("about:blank") > -1) {
    //   return false;
    // }
    return true;
  }

  _dealComponentWillUpdate(nextProps, nextState) {
    if(nextState.webUrl != this.state.webUrl || this.state.webUrl != this._customUrl) {
      this._init = true;
      nextState.url = nextState.webUrl;
      nextState.source = {uri:nextState.webUrl};
      if (nextState.webUrl.length>0) {
        this._customUrl = nextState.webUrl;
      }
    }
  }
}
